﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.IO;

namespace UnwiseSourceService.ToolClasses
{
    public static class Logger
    {
        public static void LoggError(Exception exc)
        {
            DateTime time = DateTime.Now;
            string apPath = System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath;
            StreamWriter writer = new StreamWriter(apPath + "/errorLog.txt", true);
            using (writer)
            {
                writer.WriteLine();
                writer.WriteLine("==========================================");
                string line = time.ToShortDateString() + " - " + time.ToShortTimeString() + " - " +
                    "ErrorMessage: " + exc.Message;
                writer.WriteLine(line);

                if (exc.InnerException != null)
                {
                    line = "InnerException Message: " + exc.InnerException.Message;
                    writer.WriteLine(line);
                    line = "InnerException StackTrace: " + exc.StackTrace;
                    writer.WriteLine(line);
                }

                line = "Stacktrace: " + exc.StackTrace;
                writer.WriteLine(line);
                writer.WriteLine("==========================================");
                writer.WriteLine();
            }
        }
    }
}